package org.fhm.zdte.common.service.boot;

import org.fhm.substrate.annotation.Setup;
import org.fhm.substrate.standard.IStarter;
import org.fhm.zdte.common.pojo.Request;
import org.fhm.zdte.common.pojo.Result;
import org.fhm.zdte.common.pool.ThreadPoolFactory;
import org.fhm.zdte.common.standard.IChannelDispatcher;
import org.fhm.zdte.common.standard.IThreadManager;

/**
 * The abstract implementation for {@link IStarter}.
 *
 * @author 谭波
 * @since 2023/11/17
 */
public abstract class AbstractStarter implements IStarter {

    @Setup
    private ThreadPoolFactory threadPoolFactory;

    @Setup
    private IThreadManager iThreadManager;

    @Setup
    private IChannelDispatcher iChannelDispatcher;

    @Override
    public void close() throws Exception {
        iThreadManager.notifyAllLock();
        iChannelDispatcher.closeAllChannelManager();
        threadPoolFactory.closeThreadPool();
    }

    /**
     * execute interface tasks
     *
     * @param from request a user number
     * @param bean request body
     * @return response body
     */
    public abstract Result<?> dispatchServlet(String from, Request bean);


    /**
     * execute interface tasks
     *
     * @param bean request body
     * @return response body
     */
    public abstract Result<?> dispatchInternalServlet(Request bean);

}
